<template>
  <div style="background: #5a78ec;">
    <!-- introduction -->
    <div class="box"></div>
    <div class="book_info_item">
      <div class="bookitemImg">
        <img :src="bookinfo.image" alt="" />
      </div>
      <div class="book_info_word">
        <span>{{ bookinfo.author }}</span>
        <p class="item_word">{{ bookinfo.bookName }}</p>
      </div>
      <div class="book_contain">
        <span>简介</span>
        <p>
          {{ bookinfo.details }}
        </p>
      </div>
      <div class="book_message">
        <span>信息</span>
        <div class="book_rent_list">
          <van-row>
            <van-col span="7">出租人：</van-col>
            <van-col span="17">{{ bookinfo.owner }}</van-col>
          </van-row>
          <van-row>
            <van-col span="7">借阅时长：</van-col>
            <van-col span="17">{{ bookinfo.lendTime }}天</van-col>
          </van-row>
          <van-row>
            <van-col span="7">联系电话：</van-col>
            <van-col span="17">{{ bookinfo.phone }}</van-col>
          </van-row>
          <van-row>
            <van-col span="7">取书地址：</van-col>
            <van-col span="17">{{ bookinfo.address }}</van-col>
          </van-row>
        </div>
      </div>
      <!--  -->
      <van-row>
        <van-col span="4"></van-col>
        <van-col span="16">
          <van-button
            round
            type="info"
            class="publishBtn"
            @click="getBorrowBook"
            >借阅</van-button
          >
        </van-col>
        <van-col span="4"></van-col>
      </van-row>
    </div>
  </div>
</template>

<script>
import { Dialog, Toast } from "vant";

// 埋点
// 单页应用 或 “单个页面”需异步补充 PV 日志参数还需进行如下埋点：
aplus_queue.push({
  action: "aplus.setMetaInfo",
  arguments: ["aplus-waiting", "MAN"],
});
// 单页应用路由切换后 或 在异步获取到 pv 日志所需的参数后再执行 sendPV：
aplus_queue.push({
  action: "aplus.sendPV",
  arguments: [
    { is_auto: false },
    {
      // 自定义 PV 参数 key-value 键值对（只能是这种平铺的 json，不能做多层 嵌套），如：
      miniAppId: "2001886320",
    },
  ],
});

export default {
  data() {
    return {
      bookinfo: "",
      // owner: 0,
      borrower: "",
      owner: "",
    };
  },
  methods: {
    // mgop 上传书本对应的id
    getBookOne(id) {
      const aaa = async () => {
        const res = await this.mgopfn("mgop.educational.system.selectOne", {
          id: id,
        });
        this.bookinfo = res.data;
        this.owner = res.data.owner;
        console.log(res);
      };
      aaa();
    },
    // mgop---借阅图书

    getBorrowBook() {
      const borrowBook = async () => {
        const res = await this.mgopfn("mgop.educational.system.borrowAdd", {
          bookid: this.id,
          borrower: this.borrower,
          owner: this.owner,
        });
        console.log(res);
        Toast("借阅成功");
        this.$router.push("/home");
      };
      borrowBook();
    },
  },
  mounted() {
    console.log(this.$route.query.id);
    this.id = this.$route.query.id;
    this.borrower = window.localStorage.getItem("usernameData");
    console.log("本地数据：" + this.borrower);
    // this.bookItem();

    // this.bookRent();
    // this.getBorrowBook();
    this.getBookOne(this.id);
  },
};
</script>

<style>
@media screen and (min-width: 320px) {
  .box {
    background: #5a78ec;
    width: 100%;
    height: 150px;
  }
  .book_info_item {
    width: 100%;
    height: 100%;
    /* background: pink; */
    background: #fff;
    border-radius: 44px 44px 0 0;
    text-align: center;
    padding-bottom: 40px;
  }
  .bookitemImg {
    width: 140px;
    height: 200px;
    background: #fff;
    margin: 0 auto;
    position: relative;
    top: -50px;
    display: block;
    border-radius: 22px;
    box-shadow: 0px 13px 13px 0px rgba(0, 0, 0, 0.5);
  }
  .bookitemImg img {
    width: 100%;
    height: 100%;
    border-radius: 22px;
  }
  .book_info_word {
    position: relative;
    top: -30px;
  }
  .book_info_item span {
    font-size: 12px;
  }
  .item_word {
    margin: 0;
    font-size: 16px;
    font-weight: bolder;
  }
  /*  */
  .book_contain {
    width: 90%;
    height: 20%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
    margin-bottom: 10px;
  }
  .book_contain span,
  .book_message span {
    font-size: 16px;
    font-weight: bolder;
    border-bottom: 4px solid #5a78ec;
  }
  .book_contain p {
    padding: 0 10px;
    width: 95%;
    font-size: 10px;
  }
  .book_message {
    position: relative;
    top: 20px;
    width: 90%;
    height: 40%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
  }
  .book_rent_list {
    width: 90%;
    margin: 0 auto;
    /* background: chartreuse; */
  }
  .book_rent_list .van-row {
    margin: 10px 0;
    font-size: 14px;
  }
  .publishBtn {
    margin-top: 30px;
    width: 100%;
    height: 30px;
    border-radius: 10px;
    background: #5a78ec;
  }
}
@media screen and (min-width: 375px) {
  .box {
    background: #5a78ec;
    width: 100%;
    height: 150px;
  }
  .book_info_item {
    width: 100%;
    height: 100%;
    /* background: pink; */
    background: #fff;
    border-radius: 44px 44px 0 0;
    text-align: center;
    padding-bottom: 40px;
  }
  .bookitemImg {
    width: 140px;
    height: 200px;
    background: #fff;
    margin: 0 auto;
    position: relative;
    top: -50px;
    display: block;
    border-radius: 22px;
    box-shadow: 0px 13px 13px 0px rgba(0, 0, 0, 0.5);
  }
  .bookitemImg img {
    width: 100%;
    height: 100%;
    border-radius: 22px;
  }
  .book_info_word {
    position: relative;
    top: -30px;
  }
  .book_info_item span {
    font-size: 12px;
  }
  .item_word {
    margin: 0;
    font-size: 16px;
    font-weight: bolder;
  }
  /*  */
  .book_contain {
    width: 90%;
    height: 20%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
    margin-bottom: 10px;
  }
  .book_contain span,
  .book_message span {
    font-size: 16px;
    font-weight: bolder;
    border-bottom: 4px solid #5a78ec;
  }
  .book_contain p {
    padding: 0 10px;
    width: 95%;
    font-size: 10px;
  }
  .book_message {
    position: relative;
    top: 20px;
    width: 90%;
    height: 40%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
  }
  .book_rent_list {
    width: 90%;
    margin: 0 auto;
    /* background: chartreuse; */
  }
  .book_rent_list .van-row {
    margin: 10px 0;
    font-size: 14px;
  }
  .publishBtn {
    margin-top: 30px;
    width: 100%;
    height: 30px;
    border-radius: 10px;
    background: #5a78ec;
  }
}
@media screen and (min-width: 414px) {
  .box {
    background: #5a78ec;
    width: 100%;
    height: 150px;
  }
  .book_info_item {
    width: 100%;
    height: 100%;
    /* background: pink; */
    background: #fff;
    border-radius: 44px 44px 0 0;
    text-align: center;
    padding-bottom: 40px;
  }
  .bookitemImg {
    width: 140px;
    height: 200px;
    background: #fff;
    margin: 0 auto;
    position: relative;
    top: -50px;
    display: block;
    border-radius: 22px;
    box-shadow: 0px 13px 13px 0px rgba(0, 0, 0, 0.5);
  }
  .bookitemImg img {
    width: 100%;
    height: 100%;
    border-radius: 22px;
  }
  .book_info_word {
    position: relative;
    top: -30px;
  }
  .book_info_item span {
    font-size: 12px;
  }
  .item_word {
    margin: 0;
    font-size: 16px;
    font-weight: bolder;
  }
  /*  */
  .book_contain {
    width: 90%;
    height: 20%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
    margin-bottom: 10px;
  }
  .book_contain span,
  .book_message span {
    font-size: 16px;
    font-weight: bolder;
    border-bottom: 4px solid #5a78ec;
  }
  .book_contain p {
    padding: 0 10px;
    width: 95%;
    font-size: 12px;
  }
  .book_message {
    position: relative;
    top: 20px;
    width: 90%;
    height: 40%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
  }
  .book_rent_list {
    width: 90%;
    margin: 0 auto;
    /* background: chartreuse; */
  }
  .book_rent_list .van-row {
    margin: 10px 0;
    font-size: 14px;
  }
  .publishBtn {
    margin-top: 30px;
    width: 100%;
    height: 30px;
    border-radius: 10px;
    background: #5a78ec;
  }
}
@media screen and (min-width: 768px) {
  /deep/.van-nav-bar {
    width: 100%;
    line-height: 22px;
    font-size: 26px;
  }
  /deep/.van-nav-bar__content {
    height: 80px !important;
  }
  /deep/.van-nav-bar__title {
    font-size: 26px !important;
  }
  .box {
    background: #5a78ec;
    width: 100%;
    height: 200px;
  }
  .book_info_item {
    width: 100%;
    height: 100%;
    /* background: pink; */
    background: #fff;
    border-radius: 44px 44px 0 0;
    text-align: center;
    padding-bottom: 60px;
  }
  .bookitemImg {
    width: 240px;
    height: 300px;
    background: #fff;
    margin: 0 auto;
    position: relative;
    top: -50px;
    display: block;
    border-radius: 22px;
    box-shadow: 0px 13px 13px 0px rgba(0, 0, 0, 0.5);
  }
  .bookitemImg img {
    width: 100%;
    height: 100%;
    border-radius: 22px;
  }
  .book_info_word {
    position: relative;
    top: -20px;
  }
  .book_info_item span {
    font-size: 18px;
  }
  .item_word {
    margin: 0;
    font-size: 22px;
    font-weight: bolder;
  }
  /*  */
  .book_contain {
    width: 90%;
    height: 20%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
    margin-bottom: 10px;
  }
  .book_contain span,
  .book_message span {
    font-size: 20px;
    font-weight: bolder;
    border-bottom: 4px solid #5a78ec;
  }
  .book_contain p {
    padding: 0 10px;
    width: 95%;
    font-size: 16px;
  }
  .book_message {
    position: relative;
    top: 20px;
    width: 90%;
    height: 40%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
  }
  .book_rent_list {
    width: 90%;
    margin: 0 auto;
    /* background: chartreuse; */
  }
  .book_rent_list .van-row {
    margin: 10px 0;
    font-size: 18px;
  }
  .publishBtn {
    margin-top: 50px;
    width: 100%;
    height: 50px;
    border-radius: 10px;
    background: #5a78ec;
  }
  /deep/.book_info_item span {
    font-size: 22px;
  }
  .van-dialog {
    width: 400px;
  }
  .van-dialog__message {
    font-size: 20px;
  }
  .van-dialog--round-button .van-dialog__cancel,
  .van-dialog--round-button .van-dialog__confirm {
    height: 50px;
  }
  .van-dialog--round-button .van-dialog__confirm {
    color: #fff;
    font-size: 18px;
  }
}
@media screen and (min-width: 1024px) {
  /deep/.van-nav-bar {
    width: 100%;
    line-height: 22px;
    font-size: 26px;
  }
  /deep/.van-nav-bar__content {
    height: 80px !important;
  }
  /deep/.van-nav-bar__title {
    font-size: 26px !important;
  }
  .box {
    background: #5a78ec;
    width: 100%;
    height: 300px;
  }
  .book_info_item {
    width: 100%;
    height: 100%;
    /* background: pink; */
    background: #fff;
    border-radius: 44px 44px 0 0;
    text-align: center;
    padding-bottom: 80px;
  }
  .bookitemImg {
    width: 340px;
    height: 400px;
    background: #fff;
    margin: 0 auto;
    position: relative;
    top: -50px;
    display: block;
    border-radius: 22px;
    box-shadow: 0px 13px 13px 0px rgba(0, 0, 0, 0.5);
  }
  .bookitemImg img {
    width: 100%;
    height: 100%;
    border-radius: 22px;
  }
  .book_info_word {
    position: relative;
    top: -20px;
  }
  .book_info_item span {
    font-size: 22px;
  }
  .item_word {
    margin: 0;
    font-size: 28px;
    font-weight: bolder;
  }
  /*  */
  .book_contain {
    width: 90%;
    height: 20%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
    margin-bottom: 10px;
  }
  .book_contain span,
  .book_message span {
    font-size: 24px;
    font-weight: bolder;
    border-bottom: 4px solid #5a78ec;
  }
  .book_contain p {
    padding: 0 10px;
    width: 95%;
    font-size: 18px;
  }
  .book_message {
    position: relative;
    top: 20px;
    width: 90%;
    height: 40%;
    background: #fff;
    margin: 0 auto;
    text-align: left;
  }
  .book_rent_list {
    width: 90%;
    margin: 0 auto;
    /* background: chartreuse; */
  }
  .book_rent_list .van-row {
    margin: 10px 0;
    font-size: 22px;
  }
  .publishBtn {
    margin-top: 80px;
    width: 100%;
    height: 60px;
    border-radius: 10px;
    background: #5a78ec;
  }
  /deep/.book_info_item span {
    font-size: 26px;
  }
  .van-dialog {
    width: 500px;
    height: 250px;
  }
  .van-dialog__content--isolated {
    min-height: 164px;
  }
  .van-dialog__message {
    font-size: 24px;
  }
  .van-dialog--round-button .van-dialog__cancel,
  .van-dialog--round-button .van-dialog__confirm {
    height: 50px;
  }
  .van-dialog--round-button .van-dialog__confirm {
    color: #fff;
    font-size: 20px;
  }
}
</style>
